const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path')
module.exports = {
    entry:'./src',  // 输入
    output:{
        path:path.resolve(__dirname,'../dist'), // 产出目录  输出 
        filename:'main.js'
    },
    resolve:{
        extensions:['.ts','.tsx','.js','jsx'] // 模块后缀
    },
    devServer:{     //  开发服务器基础根目录
        static:'../dist'
    },
    module:{
        rules:[
            {
                test:/\.tsx?/,
                use:'ts-loader',
                exclude:/node_modules/
            },
            { 
                test: /\.jsx?$/, 
                 use: [
                    {
                        loader: "babel-loader",
                        options: {
                            presets: [
                                "@babel/preset-env",
                                "@babel/preset-react",
                            ],
                        },
                    },
                ], 
                exclude: /node_modules/ 
            },
            {
                test:/\.css$/,
                exclude: /node_modules/ ,
                use:['style-loader','css-loader','postcss-loader']
            },
            {
                test:/\.less$/,
                exclude: /node_modules/ ,
                use:['style-loader','css-loader','less-loader','postcss-loader']
            },
        ]
    },
    plugins:[   //  插件
        new CleanWebpackPlugin({
            cleanOnceBeforeBuildPatterns:['./dist']
        }),
        new HtmlWebpackPlugin({
            template:'./src/index.html'
        })
    ]
}